import random
import itertools
from appium.webdriver.common.touch_action import TouchAction
import time
from appium import webdriver
from appium.webdriver.webdriver import WebDriver
from appium.webdriver import WebElement

if True:
    import sys
    import os
    sys.path.append(os.path.abspath('.'))
    import common

def qq_login(driver):
    #点击个人中心
    ele = driver.find_element_by_xpath(
        "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[2]"
    )
    ele.click()

    print("111")
    #点击开始登录操作
    ele = driver.find_element_by_id(
        "com.tencent.videolite.android:id/unlogin_root_view"
    )
    ele.click()
    print("222")
    #点击QQ登录

    ele = driver.find_element_by_id(
        "com.tencent.videolite.android:id/qq_layout"
    )
    ele.click()
    print("333")
    #获取用户信息

    #点击登录
    ele = driver.find_element_by_xpath(
        "/hierarchy/android.widget.FrameLayout/android.widget.RelativeLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.RelativeLayout[2]/android.widget.LinearLayout/android.widget.Button"
    )
    ele.click()
    time.sleep(8)
    try:
        print("444")
        ele = driver.find_element_by_id(
            "com.tencent.videolite.android:id/login_type"
        )
        print("QQ授权登录成功")
    except:
        print("QQ授权登录不成功")

def wx_login(driver):
    #点击个人中心
    ele = driver.find_element_by_xpath(
        "/hierarchy/android.widget.FrameLayout/android.widget.LinearLayout/android.widget.FrameLayout/android.widget.RelativeLayout/android.support.v7.widget.RecyclerView/android.widget.LinearLayout[2]"
    )
    ele.click()
    print("111")
    #点击开始登录操作
    ele = driver.find_element_by_id(
        "com.tencent.videolite.android:id/unlogin_root_view"
    )
    ele.click()
    print("222")
    #点击微信登录
    ele = driver.find_element_by_id(
        "com.tencent.videolite.android:id/wx_layout"
    )
    ele.click()
    print("333")

    # #点击确认登录
    # ele = driver.find_element_by_id(
    #     "com.tencent.mm:id/cqc"
    # )
    # ele.click()
    # print("444")

    time.sleep(8)
    try:
        print("444")
        ele = driver.find_element_by_id(
            "com.tencent.videolite.android:id/login_type"
        )
        print("微信授权登录成功")
    except:
        print("微信授权登录不成功")